
import Vue from 'vue'
import md5 from 'js-md5';
let URL = 'https://admin.51zhandashi.com'
Vue.prototype.URL = URL;

var i = 1;
var time = -5000;
const http = (url, method, data,isToken = true) => {
  return new Promise(function (resolve, reject) {
	if (isToken || isToken == null) {
	  	data.token = uni.getStorageSync('userinfo').token || '';
	data.user_id = uni.getStorageSync('userinfo').id || '';
	}
	
    uni.request({
      url: URL+url || '',
      method: method || 'get',
      data: data || null,
      header: {
        "Content-Type": "application/x-www-form-urlencoded", // application/json
      },
      success: function (res) {
		  console.log('fdfd',res.data.sta);
        if (res.data.sta == 200) {
			// console.log(res);
        }else if(res.data.sta==2002){
			uni.navigateTo({
				url:'/pages/login/login'
			})
		}
		uni.hideLoading();
        resolve(res.data);
      },
      fail: function (err) {
        reject({ error: '网络错误' });
      },
    })
  })
}

export default http